package intelligentrecommender.phases.test;

import edu.stanford.nlp.ie.AbstractSequenceClassifier;
import edu.stanford.nlp.ie.crf.*;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;

import java.util.List;
import java.io.IOException;

/**
 * This is a demo of calling CRFClassifier programmatically.
 * <p>
 * Usage:
 * <code> java -mx400m -cp "stanford-ner.jar:." NERDemo [serializedClassifier [fileName]]</code>
 * <p>
 * If arguments aren't specified, they default to
 * ner-eng-ie.crf-3-all2006.ser.gz and some hardcoded sample text.
 * <p>
 * To use CRFClassifier from the command line: java -mx400m
 * edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier [classifier] -textFile
 * [file] Or if the file is already tokenized and one word per line, perhaps in
 * a tab-separated value format with extra columns for part-of-speech tag, etc.,
 * use the version below (note the 's' instead of the 'x'): java -mx400m
 * edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier [classifier] -testFile
 * [file]
 *
 * @author Jenny Finkel
 * @author Christopher Manning
 */
public class NERDemo {

    public static void main(String[] args) throws IOException {

        String serializedClassifier = "src/intelligentrecommender/phases/test/classifiers/english.all.3class.distsim.crf.ser.gz";

        AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifierNoExceptions(serializedClassifier);

        String s1 = "Good afternoon Rajat Raina, how are you today?";
        String s2 = "I go to school at Stanford University, which is located in California.";
        String s3 = "modern period early demographic politics political party zone palestinian territory feature "
                + "download oslo accord classical antiquity middle age overview feature whitepaper ancient period "
                + "national internet view arabic world today' top story blame victim spurious scholarship palestinian "
                + "question 11 palestine guide ottoman palestine 1800 1914 international journal middle east study "
                + "tel aviv dream city war word break australia' decision abstain unite nation vote give palestine "
                + "non-member observer state status encyclopedia world history sixth edition march 03 2013 reshape "
                + "palestine muhammad alus british mandate 1831 1922 news bulletin american school oriental research "
                + "technology holy land history think papers submit international conference relation holy land world "
                + "outside johannesburg 1986 travel entertainment money business user-pay nbn cop analyst view business "
                + "continuity plan survival guide significantly improve storage efficiency remote office datum "
                + "protection system availability small business see benefit nbn report nbn oversight fall victim "
                + "partisanship current demographic nsw work write compile since 1945 work write 1918 map nz "
                + "case study enable real-time data-drive decision personal tool latest job feeddemon namespace "
                + "nsw hp cio priority resource centre nsw reinvent antivirus variant dead link palaestina "
                + "prima enable cookie firefox palaestina secunda enable cookie internet explorer invention "
                + "ancient israel silence palestinian history australian großer atla zur weltgeschichte "
                + "cookie must enable innocent abroad palaestina secunda real estate palestine moslem description "
                + "syrium holy land 650 1500 palaestina prima search brisbanetime map history middle east "
                + "jund filastin national time late ottoman british mandate period november 2010 filastin "
                + "popular whitepaper enable cookie google chrome palestine palaestina palestine palaestina "
                + "ii find babysitter west bank job business continuity plan survival guide inevitable "
                + "extinction pst virtual storage make simple contents south southwest asia etymology "
                + "use external link may follow wikipedia' policy guideline datum centre consolidation "
                + "restructure cost continue growth computerworld newsletter nsw demographic wa nsw "
                + "history nsw boundary jew muslim arab world haunt past real imagine nsw fatah politics "
                + "violence institutionalization popular struggle israel portal vic legal aspect palestine "
                + "problem special regard question jerusalem palestine portal palestinian make people "
                + "middle east portal vic wa wa nsw urdunn people western asia protection conservation "
                + "valorisation palestinian cultural patrimony arab zionism world war asia portal "
                + "population palestine geography portal international organization interim report "
                + "civil administration palestine islam history idea people event middle east jund "
                + "al-urdunn see also reference bibliography external link navigation menu history palestine "
                + "palestinian palestine political status 1916-22 proposal nsw 1947 actual historic region "
                + "palestine nsw 1947 proposal state israel israeli-occupy territory nsw name definition map "
                + "history middle east palestine palestine mercer dictionary bible encyclopedia ottoman empire "
                + "bruce alan master gábor ágoston divide economy mandatory palestine nsw emergence "
                + "palestinian-arab national movement 1918 1929 nsw land economy ancient palestine nsw "
                + "find news nsw vic update prosopography later roman empire volume iii ad 527 641 nsw "
                + "@newscomauhq nsw history israel rise zionism time history modern palestine one land "
                + "two people oxford guide people place bible frontier state late ottoman empire transjordan "
                + "1850-1921 history ancient palestine exclusive oxford history biblical world history "
                + "palestine ottoman conquest found state israel lithic stone age handbook stone tool levant "
                + "placename world origin meaning name 600 country city territory natural feature historic "
                + "site boundary modern palestine 1840 1947 sign youtube sign youtube sign youtube sign youtube "
                + "10 pm sign youtube 11 pm sign youtube sign youtube sign youtube sign youtube sign youtube "
                + "palestine israel histor";

        for (List<CoreLabel> lcl : classifier.classify(s3)) {
            for (CoreLabel cl : lcl) {
                System.out.println(cl);
                if ("LOCATION".equals(cl.getString(CoreAnnotations.AnswerAnnotation.class))) {
                    System.out.println(cl.getString(CoreAnnotations.TextAnnotation.class));
                }
            }
        }
    }
}